import Vue from 'vue';
import Router from 'vue-router';

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router);

/* Layout */
import Layout from '@/views/layout/Layout'; //灰色背景
import LayoutWhite from '@/views/layout/LayoutWhite'; //白色背景
// import Layout from '@/views/layout';
// import LayoutWhite from '@/views/layout/index'; //此时两者一样的

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [{
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [{
      path: '/redirect/:path*',
      component: () => import('@/views/redirect/index')
    }]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    name: '错误页面',
    hidden: true
  },
  //----------------------------------------------------
  {
    path: '/index',
    component: () => import('@/views/firstpage/index'), //src\views\firstpage\index.vue
    name: '商品首面',
    hidden: true
  },
  ////////用层包裹///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  {
    path: '',
    component: LayoutWhite, //白色背景
    // redirect: 'splist',
    name: '购物',
    meta: {
      title: '购物',
      icon: 'dashboard'
    },
    children: [{
        path: 'splist',
        component: () => import('@/views/shoppinglist/index'),
        name: 'shoppinglist',
        meta: {
          title: '商品列表',
          icon: 'dashboard',
          noCache: true
        }
      },
      {
        path: 'spselect',
        component: () => import('@/views/shoppingselect/index'),
        name: 'shoppingselect',
        meta: {
          title: '商品选择',
          icon: 'dashboard',
          noCache: true
        }
      },
      {
        path: 'spcart',
        component: () => import('@/views/shoppingcart/index'),
        name: 'shoppingcart',
        meta: {
          title: '购物车',
          icon: 'dashboard',
          noCache: true
        }
      },
    ]
  },

  {
    path: '',
    component: Layout, //灰色背景
    // redirect: 'splist2',
    name: '商品列表2',
    meta: {
      title: '商品列表',
      icon: 'dashboard'
    },
    hidden: true,
    children: [{
        path: 'splist/pending/:id(\\d+)',
        name: 'splist-pending',
        meta: {
          title: '商品列表',
          icon: 'dashboard'
        },
        component: () => import('@/views/shoppinglist/index'), //src\views\spacepage\index.vue
        hidden: true
      },
      {
        path: 'mycenter',
        name: 'mycenter',
        meta: {
          title: '个人中心',
          icon: 'dashboard'
        },
        component: () => import('@/views/mycenter/index'), //src\views\mycenter\index.vue
        hidden: true
      },
    ]
  },
];


export default new Router({
  // mode: 'history', //后端支持可开  
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRouterMap, //   createMyRouter()
});
